package com.example.content_android.ui.articleList;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.EditText;
import android.widget.TextView;


import com.alibaba.fastjson.JSON;
import com.example.content_android.R;

import org.json.JSONException;
import org.json.JSONObject;
import org.sufficientlysecure.htmltextview.HtmlHttpImageGetter;
import org.sufficientlysecure.htmltextview.HtmlTextView;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ArticleDetailActivity extends AppCompatActivity {
    public TextView articleDetailTitle = null;
    public TextView articleDetailAuthor = null;
    public TextView articleDetailCreateDate = null;
    public TextView articleDetailRemark = null;
    public HtmlTextView articleDetailContent = null;


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        //隐藏界面默认标题栏
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        //设置顶部状态栏黑底白字（最上面这一行显示电池、时钟、wifi等图标是状态栏）
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(Color.BLACK);
        }
        setContentView(R.layout.activity_article_detail);
        init();
        Intent intent = getIntent();
        //反序列化数据对象
        Serializable se = intent.getSerializableExtra("articleDetail");
        if (se instanceof ArticleDetailBean) {
            //获取到携带数据的DataBean对象db
            ArticleDetailBean db = (ArticleDetailBean) se;
            System.out.println(db.getTitle());
            System.out.println(db.getContent());
            articleDetailTitle.setText(db.getTitle());
            articleDetailContent.setHtml(db.getContent(), new HtmlHttpImageGetter(articleDetailContent));
//            articleDetailContent.setText(db.getContent());
            //滚动条设置
            articleDetailContent.setMovementMethod(ScrollingMovementMethod.getInstance());
            articleDetailRemark.setText(db.getRemark());
            articleDetailCreateDate.setText(db.getCreateDate());
            articleDetailAuthor.setText(db.getCreateName());

        }



    }

    public void  init(){


        articleDetailTitle = findViewById(R.id.article_detail_title);
        articleDetailAuthor = findViewById(R.id.article_detail_author);
        articleDetailCreateDate = findViewById(R.id.article_detail_createDate);
        articleDetailRemark = findViewById(R.id.article_detail_remark);
        articleDetailContent = findViewById(R.id.article_detail_content);
    }
}